<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>代理模式</title>
</head>
<body>
	<script type="text/javascript">
		const images = (() => {
			let imgNode = document.createElement('img');
				document.body.appendChild(imgNode);
				return {
					setSrc: (src) => {
						imgNode.src = src;
					}
				}
		})()
		images.setSrc('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1493811901324&di=48e2133b7b3ae9759a2c1a71884290f9&imgtype=0&src=http%3A%2F%2Fpic38.nipic.com%2F20140228%2F8821914_204428973000_2.jpg');
		// 缓存代理
		 const mutl = function () {
		 	let a  = 1;
		 	console.log('aaa');
		 	for (let i = 0; i < arguments.length; i++) {
		 		 a *= arguments[i];
		 	}
		 	return a;
		 }

		 const proxyMult = function (fn) {
		 	let cache = {};
		 		return function () {
		 			let arg = Array.prototype.join.call(arguments, ',');
		 			if (arg in cache) {
		 				return cache[arg];
		 			}
		 			return cache[arg] = fn.apply(this, arguments);
		 		}
		 }
		 proxyMults = proxyMult(mutl)
		 console.log(proxyMults(1,2,3,4));
		 console.log(proxyMults(1,2,3,4));
		 console.log(proxyMults(1,2,4));
		 console.log(proxyMults(1,2,3,4));
	</script>
</body>
</html>